﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test_GoogleAPI.aspx.cs" Inherits="sandbox_testGoogleAPI" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">

    google.load("language", "1");

    function translate() {
      var text = document.getElementById("tb2").value;
      alert(text);
      google.language.detect(text, function(result) {
        if (!result.error && result.language) {
          google.language.translate(text, result.language, "zh-tw",
                                    function(result) {
            var translated = document.getElementById("translation");
            if (result.translation) {
              translated.innerHTML = result.translation;
            }
          });
        }
      });
    }


    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:TextBox ID="tb2" runat="server" Height="260px" Width="316px"></asp:TextBox>
        <a onclick="translate()">trans</a>
        <div id="translation"></div>
    </div>
    </form>
</body>
</html>
